#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include <stdlib.h>

int pid = 0;

void alarmsign_handler(int SignNo){
    if (fork() == 0) {
        kill(pid, SIGUSR1);
    }
}

int main(int argc, char* argv[]){
    pid = atoi(argv[1]);
    signal(SIGALRM, alarmsign_handler);

    struct itimerval itv;
    itv.it_interval.tv_sec = atoi(argv[2]); //定时周期为atoi(argv[2])秒
    itv.it_interval.tv_usec = 0;
    itv.it_value.tv_sec = 1; //定时器启动以后将在1秒后正式开始计时。
    itv.it_value.tv_usec = 0;

    setitimer(ITIMER_REAL, &itv, NULL);
    
    while(1){
        usleep(500);
    }
    
    return 0;
}

